#include <stdio.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>

#include <stdlib.h>

void * thread_func(void *arg)
{
    printf("new thread:%ld\n", pthread_self());
    sleep(1);
    /* 线程退出 */
    //int * retStatus =(int *)malloc(sizeof(int) * 1);
    //*ret = -45;
    static int retStatus = -45;//加 static 防止栈空间里的值被释放
    pthread_exit(&retStatus);
}

int main()
{
    /* 线程的创建 */
    pthread_t tid;
    int ret = pthread_create(&tid, NULL, thread_func, NULL);
    if (ret != 0)
    {
        printf("pthread_create rror\n");
        exit(-1);
    }
    printf("tid:%ld\n", tid);
    printf("main thread:%ld\n", pthread_self());

    /* 阻塞等待回收 */
    /* 回收子线程的资源 */
    int * retStatus = NULL;
    pthread_join(tid, (void **)&retStatus);

    printf("retStatus:%d\n", *retStatus);

    return 0;
}